package com.contexticon.mediaTest;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JFrame;

import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.test.VlcjTest;

/**
 * An absolute minimum test player.
 */
public class MinimalPlayer extends VlcjTest {

	public static void main(String[] args) throws Exception {

		String nameOS = "os.name";
		String versionOS = "os.version";
		String architectureOS = "os.arch";
		String javaVersion = "java.version";
		System.out.println("\n  The information about OS");
		System.out.println("\nName of the OS: " + System.getProperty(nameOS));
		System.out.println("Version of the OS: "
				+ System.getProperty(versionOS));
		System.out.println("Architecture of THe OS: "
				+ System.getProperty(architectureOS));
		System.out.println("Java version:  " + System.getProperty(javaVersion));

		System.out.println("Working Directory = "
				+ System.getProperty("user.dir"));

		File file = new File("VLC.app/Contents/MacOS/lib/");
		if (isMac()) { // Mac OS
			System.out.println("I am on a mac");
			
			System.setProperty("jna.library.path",
					"VLC.app/Contents/MacOS/lib/");
		} else if (isWindows()) { //Windows 
			System.out.println("I am on windows");
			
			if (System.getProperty(architectureOS).equals("x86_64")) {
				System.out.println("I am on windows x86_64");
				
				System.setProperty("jna.library.path", "Win64\\");
			}
			else if (System.getProperty(architectureOS).equals("amd64")) {
				System.out.println("I am on Tills computer!");
				//System.setProperty("jna.library.path", "C:\\Users\\Till\\Desktop\\VLC builds\\Win64\\");
				System.setProperty("jna.library.path", "Win64\\");
			}
			// Windows 64
			else {
				System.out.println("I am on windows 32");
			// Windows 32
				System.setProperty("jna.library.path", "Win32\\");
			}
			

		}

		/**
		 * if(args.length != 1) { System.out.println("Specify an MRL to play");
		 * System.exit(1); }
		 **/

		final EmbeddedMediaPlayerComponent mediaPlayerComponent = new EmbeddedMediaPlayerComponent();

		JFrame f = new JFrame("Test Player");
		// f.setIconImage(new
		// ImageIcon(MinimalPlayer.class.getResource("/icons/vlcj-logo.png")).getImage());
		f.setSize(800, 600);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				mediaPlayerComponent.getMediaPlayer().stop();
				mediaPlayerComponent.release();
			}
		});
		f.setContentPane(mediaPlayerComponent);
		f.setVisible(true);

		MovieChooser chooser = new MovieChooser();
		chooser.setMediaPlayer(mediaPlayerComponent.getMediaPlayer());
		chooser.setVisible(true);

		Thread.currentThread().join();
	}
	
	public static boolean isWindows() {
		 
		String os = System.getProperty("os.name").toLowerCase();
		// windows
		return (os.indexOf("win") >= 0);
 
	}
 
	public static boolean isMac() {
 
		String os = System.getProperty("os.name").toLowerCase();
		// Mac
		return (os.indexOf("mac") >= 0);
 
	}
 
	public static boolean isUnix() {
 
		String os = System.getProperty("os.name").toLowerCase();
		// linux or unix
		return (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0);
 
	}
 
	public static boolean isSolaris() {
 
		String os = System.getProperty("os.name").toLowerCase();
		// Solaris
		return (os.indexOf("sunos") >= 0);
 
	}
	
	
}
